package com.bupt.liutong.admin.shop.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.core.base.BaseAction;
import com.bupt.liutong.admin.shop.bo.ProdTypeBo;
import com.bupt.liutong.admin.shop.form.ProdTypeForm;
import com.bupt.liutong.util.BeanUtils;

public class ProdTypeAction extends BaseAction {

	private ProdTypeBo prodTypeBo;
	
	public ActionForward getProdTypesByPage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ProdTypeForm prodTypeForm = (ProdTypeForm) form;
		request.setAttribute("prodTypeFormList", prodTypeBo.getProdTypesByPage(prodTypeForm, request));
		putPageInfo(request, prodTypeForm);
		return mapping.findForward("getProdTypesByPageSuccess");
	}
	
	public ActionForward insertProdType(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		request.setAttribute("prodTypeFormList", prodTypeBo.getAllProdTypes());
		return mapping.findForward("insertProdTypeSuccess");
	}
	
	public ActionForward insertProdTypeDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ProdTypeForm prodTypeForm = (ProdTypeForm) form;
		prodTypeBo.insertProdType(prodTypeForm);
		return mapping.findForward("insertProdTypeDoSuccess");
	}
	
	public ActionForward updateProdType(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ProdTypeForm prodTypeForm = (ProdTypeForm) form;
		BeanUtils.copyProperties(prodTypeForm, prodTypeBo.getProdTypeById(prodTypeForm));
		request.setAttribute("prodTypeFormList", prodTypeBo.getAllProdTypes());
		return mapping.findForward("updateProdTypeSuccess");
	}
	
	public ActionForward updateProdTypeDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ProdTypeForm prodTypeForm = (ProdTypeForm) form;
		prodTypeBo.updateProdType(prodTypeForm);
		return mapping.findForward("updateProdTypeDoSuccess");
	}
	
	public ActionForward deleteProdTypes(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String[] ids = request.getParameterValues("id");
		prodTypeBo.deleteProdTypes(ids);
		return mapping.findForward("deleteProdTypesSuccess");
	}

	public void setProdTypeBo(ProdTypeBo prodTypeBo) {
		this.prodTypeBo = prodTypeBo;
	}
}
